package com.bdsoft.controller;

import java.util.List;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.bdsoft.domain.CmsBanner;
import com.bdsoft.service.ICmsBannerService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 内容-横幅广告Controller
 * 
 * @author dumingshen
 * @date 2025-10-29
 */
@RestController
@RequestMapping("/cotentdms/banner")
public class CmsBannerController extends BaseController
{
    @Autowired
    private ICmsBannerService cmsBannerService;

    /**
     * 查询内容-横幅广告列表
     */
    @PreAuthorize("@ss.hasPermi('cotentdms:banner:list')")
    @GetMapping("/list")
    public TableDataInfo list(CmsBanner cmsBanner)
    {
        startPage();
        List<CmsBanner> list = cmsBannerService.selectCmsBannerList(cmsBanner);
        return getDataTable(list);
    }

    /**
     * 导出内容-横幅广告列表
     */
    @PreAuthorize("@ss.hasPermi('cotentdms:banner:export')")
    @Log(title = "内容-横幅广告", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CmsBanner cmsBanner)
    {
        List<CmsBanner> list = cmsBannerService.selectCmsBannerList(cmsBanner);
        ExcelUtil<CmsBanner> util = new ExcelUtil<CmsBanner>(CmsBanner.class);
        util.exportExcel(response, list, "内容-横幅广告数据");
    }

    /**
     * 获取内容-横幅广告详细信息
     */
    @PreAuthorize("@ss.hasPermi('cotentdms:banner:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(cmsBannerService.selectCmsBannerById(id));
    }

    /**
     * 新增内容-横幅广告
     */
    @PreAuthorize("@ss.hasPermi('cotentdms:banner:add')")
    @Log(title = "内容-横幅广告", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CmsBanner cmsBanner)
    {
        return toAjax(cmsBannerService.insertCmsBanner(cmsBanner));
    }

    /**
     * 修改内容-横幅广告
     */
    @PreAuthorize("@ss.hasPermi('cotentdms:banner:edit')")
    @Log(title = "内容-横幅广告", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CmsBanner cmsBanner)
    {
        return toAjax(cmsBannerService.updateCmsBanner(cmsBanner));
    }

    /**
     * 删除内容-横幅广告
     */
    @PreAuthorize("@ss.hasPermi('cotentdms:banner:remove')")
    @Log(title = "内容-横幅广告", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(cmsBannerService.deleteCmsBannerByIds(ids));
    }
}
